package com.example.yls.demoa;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity implements IOnUpdataListener {
    MyReceiver receiver;
    TextView textTime;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        receiver = new MyReceiver(MainActivity.this);
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIME_TICK);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        registerReceiver(receiver,filter);
        updateTime();
    }
    @Override
    public void updateTime(){
        Calendar calendar = Calendar.getInstance();
        textTime = findViewById(R.id.textTime);
        textTime.setText(calendar.get(Calendar.HOUR)+":"+ calendar.get(Calendar.MINUTE));
    }
}
